package com.items.TreeUtil;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.items.Dao.UnitsMapper;
import com.items.Entity.UnitsBO;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.List;

@SpringBootTest
public class TreeDemo {

    @Resource
    private UnitsMapper unitsMapper;

    public void test() {
        List<UnitsBO> list = unitsMapper.selectList(
                new LambdaQueryWrapper<>());
        ITreeUtilImpl<UnitsBO, Integer> treeUtil = new ITreeUtilImpl<>(list);
        treeUtil.setCodeFunc(UnitsBO::getId);
        treeUtil.setParentFunc(UnitsBO::getParentId);
        treeUtil.setListFunc(UnitsBO::getChildren);
        treeUtil.setConsumer(UnitsBO::setChildren);
        List<UnitsBO> tree = treeUtil.getTreeList(unitsMapper.selectList(new LambdaQueryWrapper<>()));
        System.out.println(tree);
    }
}
